/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manejadores;

import beans2.Atributo;
import java.sql.*;
import java.util.ArrayList;

/**
 *
 * @author Jose Dario Gimenez
 */
public class ManejadorAtributo {

    private Atributo atributo;
    private ResultSet resultSet;
    private ArrayList list;
    private Connection connection;

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public void setConditionRecurso(String condition) throws SQLException {
        if (!condition.equalsIgnoreCase("")) {
            condition = " and " + condition;
        }
        list = new ArrayList();
        PreparedStatement statement = connection.prepareStatement("select atributo.idatributo, atributo.nombre, recurso_tiporecurso_atributo.valor from atributo, recurso_tiporecurso_atributo where atributo.idatributo=recurso_tiporecurso_atributo.idatributo" + condition + " order by atributo.idatributo");
        resultSet = statement.executeQuery();
        while (resultSet.next()) {
            atributo = new Atributo();
            atributo.setId(resultSet.getInt(1));
            atributo.setNombre(resultSet.getString(2));
            atributo.setValor(resultSet.getString(3));
            list.add(atributo);
        }
    }

    public void setConditionTipoRecurso(String condition) throws SQLException {
        if (!condition.equalsIgnoreCase("")) {
            condition = " and " + condition;
        }
        list = new ArrayList();
        PreparedStatement statement = connection.prepareStatement("select atributo.idatributo, atributo.nombre from atributo, tiporecurso_atributo where atributo.idatributo=tiporecurso_atributo.idatributo" + condition + " order by atributo.idatributo");
        resultSet = statement.executeQuery();
        while (resultSet.next()) {
            atributo = new Atributo();
            atributo.setId(resultSet.getInt(1));
            atributo.setNombre(resultSet.getString(2));
            list.add(atributo);
        }
    }

    public ArrayList getList() {
        return list;
    }
}
